const app = getApp()
const radio_code = 'FM_101.5'
const backgroundAudioManager = wx.getBackgroundAudioManager()
import {
  radio_play_list,
  share_by_property,
  radio_title_update
} from '../../api/request'

Page({
  data: {
    play_online_tag: false,
    action: {
      method: 'pause'
    },

    living_url: 'https://yz.2alive.cn:8082/live/1499/64k.mp3',
    //直播地址 https://lhttp.qingting.fm/live/1499/64k.mp3
    edit: '0', //可编辑
    play_list: [], //节目播放清单
    property_code: '',
  },

  player(e) {
    var m_index = e.currentTarget.dataset.index
    backgroundAudioManager.title = this.data.play_list[m_index].RADIO_TITLE
    backgroundAudioManager.epname = '此时此刻'
    backgroundAudioManager.singer = '重庆经济广播电台'
    backgroundAudioManager.coverImgUrl = this.data.play_list[m_index].RADIO_FM
    backgroundAudioManager.src = this.data.play_list[m_index].RADIO_URL
    console.log('day=' + this.data.play_list[m_index].RADIO_URL)
    backgroundAudioManager.play()
  },

  player_online() {
    wx.setKeepScreenOn({
      keepScreenOn: true,
    })
    if (this.data.play_online_tag) {
      this.setData({
        action: {
          method: 'pause' //暂停
        }
      })
      this.setData({
        play_online_tag: false,
      })
    } else {
      this.setData({
        action: {
          method: 'play' //播放
        }
      })
      this.setData({
        play_online_tag: true,
      })
    }

  },

  onLoad: function (options) {
    var data = {
      para: [radio_code,
        app.globalData.cur_my_openid
      ]
    }
    radio_play_list(data).then(res => {
      this.setData({
        play_list: res.data,
      })

      if (res.data[0].EDITOR == '1') {
        //主题可编辑
        this.setData({
          edit: '1',
          property_code: options.property_code
        })
      }

    })
  },

  //小程序分享信息查询
  share_by_property(property_code) {
    var data = {
      para: [property_code]
    }
    share_by_property(data).then(res => {
      app.globalData.share_title = res.data[0].SHARE_TITLE
      app.globalData.share_img_url = res.data[0].SHARE_IMG_URL

      this.user_log_record(app.globalData.cur_my_openid, app.globalData.cur_my_name, '', '', app.globalData.cur_property_code,
        app.globalData.cur_property_name, '1', '1', '1')
    })
  },



  //节目主题修改  
  input_ok(e) {
    var data = {
      para: [radio_code,
        e.currentTarget.id,
        e.detail.value,
        '',
        app.globalData.cur_my_openid
      ]
    }
    radio_title_update(data).then(res => {})
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.setKeepScreenOn({
      keepScreenOn: false,
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  //分享朋友圈
  onShareTimeline: function () {
    return {
      title: app.globalData.signature_name + app.globalData.cur_property_name + '业主对话经广台《物业面对面》FM101.5',
      query: 'property_code=' + this.data.property_code,
      imageUrl: 'https://yz.2alive.cn/image/logo.png',
    }
  },

  // 用户点击右上角分享
  onShareAppMessage: function () {
    return {
      title: app.globalData.signature_name + app.globalData.cur_property_name + '业主对话经广台《物业面对面》...FM101.5',
      path: '/pages/radio/index?property_code=' + this.data.property_code,
      imageUrl: 'https://yz.2alive.cn/image/fm101_share.png',
    }
  },

})